package com.cq.hd.order.controller;

import com.cq.hd.common.response.Result;
import com.cq.hd.common.response.ResultGenerator;
import com.cq.hd.order.api.TbOrderItemApi;
import com.cq.hd.order.api.dto.OrderItemDto;
import com.cq.hd.order.api.vo.MerchantOrderAmtStatVo;
import com.cq.hd.order.api.vo.OrderItemVo;
import com.cq.hd.order.po.TbOrderItemPo;
import com.cq.hd.order.service.TbOrderItemService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TbOrderItemController implements TbOrderItemApi {

    @Autowired
    private TbOrderItemService orderItemService;

    @Override
    public Result<List<OrderItemVo>> listByActiveIds(@RequestBody List<Long> activeIds) {
        return ResultGenerator.success(orderItemService.listByActiveIds(activeIds));
    }

    @Override
    public Result<List<OrderItemVo>> listByDto(OrderItemDto orderItemDto) {
        return ResultGenerator.success(orderItemService.listByDto(orderItemDto));
    }

    @Override
    public Result<OrderItemVo> getByVerifyCode(String verifyCode) {
        return ResultGenerator.success(orderItemService.getByVerifyCode(verifyCode));
    }

    @Override
    public Result<MerchantOrderAmtStatVo> getMerchantWaitSettleAmt(Long merchantId) {
        return ResultGenerator.success(orderItemService.getMerchantWaitSettleAmt(merchantId));
    }

    @Override
    public Result<OrderItemVo> getById(Long id) {
        TbOrderItemPo po = orderItemService.getById(id);
        if (po == null) {
            return null;
        }
        OrderItemVo vo = new OrderItemVo();
        BeanUtils.copyProperties(po, vo);
        return ResultGenerator.success(vo);
    }
}
